package com.ruoyi.platform.system.role.pojo;

import com.ruoyi.platform.system.role.enums.RoleEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Optional;

/**
 * 角色
 *
 * @author lcf
 */
@Data
@ApiModel
@NoArgsConstructor
public class RoleDTO {
    /**
     * 角色code
     */
    @ApiModelProperty("角色code")
    private Integer code;
    /**
     * 角色名称
     */
    @ApiModelProperty("角色名称")
    private String name;

    public RoleDTO(RoleEnum roleEnum) {
        this.code = roleEnum.getCode();
        this.name = roleEnum.getRoleName();
    }

    public RoleDTO(int code) {
        Optional.ofNullable(RoleEnum.ofCode(code)).ifPresent(role -> {
            this.code = role.getCode();
            this.name = role.getRoleName();
        });
    }
}
